rm(list = setdiff(ls(), lsf.str()))
#load data
load("Study 1/Original Data (shareable)/Study1_dataverse_Netherlands2014.RData")

#Coding
#sex----
data$female<- ifelse(as.numeric(data$sex)==2,1,0)

#age----
data$age<-data$LFT

#Income -----
data$income<-car::recode(as.numeric(data$w1_q65), "2=1;3=1;4=1;5=2;6=3;7=4;8=5;9=6;10=7;11=8;12=9;13=NA;14=NA")
data$income<-zero1(data$income)
data$income[is.na(data$income)==TRUE]=2
data$income_missing<- ifelse(data$income==2, 1,0)

#Education--------------
data$prep_secon <- ifelse(as.numeric(data$education)==2,1,0)
data$highschool <- ifelse(as.numeric(data$education)==3,1,0)
data$secondary_vocation <- ifelse(as.numeric(data$education)==4,1,0)
data$pre_uni <- ifelse(as.numeric(data$education)==5,1,0)
data$college <- ifelse(as.numeric(data$education)==6,1,0)
data$uni <- ifelse(as.numeric(data$education)==7,1,0)

#lr-ideology
data$lr_ideology<-car::recode(as.numeric(data$w1_q29), "12=NA")

#Openness-------
data$w5_open1<-as.numeric(data$w5_open1) #*1: "Have a vivid imagination"
data$w5_open2_rec<-6-as.numeric(data$w5_open2) #2: "Am not interested in abstract ideas" (reversed)
data$w5_open3_rec<-6-as.numeric(data$w5_open3)  #3: "Have difficulty understanding abstract ideas" (reversed)
data$w5_open4_rec<-6-as.numeric(data$w5_open4) #4: "Do not have a good imagination" (reversed
data$w5_open<-rowMeans(data.frame(data$w5_open1, data$w5_open2_rec, data$w5_open3_rec, data$w5_open4_rec), na.rm=T)

#Conscientiousness-------
data$w5_con1<-as.numeric(data$w5_con1) #*1: "Get chores done right away" 
data$w5_con2<-as.numeric(data$w5_con2)#*2: "Like order"
data$w5_con3_rec<-6-as.numeric(data$w5_con3) #*3: "Make a mess of things" (Reversed)
data$w5_con4_rec<-6-as.numeric(data$w5_con4)#*4: "Often forget to put things back in their proper place" (Reversed)
data$w5_con<-rowMeans(data.frame(data$w5_con1, data$w5_con2, data$w5_con3_rec, data$w5_con4_rec), na.rm=T)

#Extraversion -------
data$w5_ext1<-as.numeric(data$w5_ext1)#1: "Am the life of the party"
data$w5_ext2<-as.numeric(data$w5_ext2)#2: "Talk to a lot of different people at parties"
data$w5_ext3_rec<-6-as.numeric(data$w5_ext3)#*3: "Don't' talk a lot" (Reversed)
data$w5_ext4_rec<-6-as.numeric(data$w5_ext4)#*4: "Keep in the background" (Reversed)
data$w5_extra<-rowMeans(data.frame(data$w5_ext1, data$w5_ext2, data$w5_ext3_rec, data$w5_ext4_rec), na.rm=T)

#Agreeableness-------
data$w5_agre1<-as.numeric(data$w5_agr1)#*1: "Sympathize with others' feelings"
data$w5_agre2<-as.numeric(data$w5_agr2)#*2: "Feel others' emotions"
data$w5_agre3_rec<-6-as.numeric(data$w5_agr3)#*3: "Am not interested in other people's problems" (Reversed)
data$w5_agre4_rec<-6-as.numeric(data$w5_agr4)#*4: "Am not really interested in others" (Reversed)
data$w5_agre<-rowMeans(data.frame(data$w5_agre1, data$w5_agre2, data$w5_agre3_rec, data$w5_agre4_rec), na.rm=T)

#Neuroticism-------
data$w5_neu1<-as.numeric(data$w5_neu1)#*1: "Get upset easily"
data$w5_neu2<-as.numeric(data$w5_neu2)#*2: "Have frequent mood swings"
data$w5_neu3_rec<-6-as.numeric(data$w5_neu3)#*3: "Am relaxed most of the time" (Reversed)
data$w5_neu4_rec<-6-as.numeric(data$w5_neu4)#*4: "Seldom feel blue" (Reversed)
data$w5_neu<-rowMeans(data.frame(data$w5_neu1, data$w5_neu2, data$w5_neu3_rec, data$w5_neu4_rec), na.rm=T)

#Multinomial vote: government opposition
data$w1_pvv_govopp<-car::recode(as.numeric(data$w1_q36), "1=2; 3=1; 4=3; 5=3; 6=3; 7=3; 8=3; 9=3; 10=3; 11=3; 12=3; 13=NA; 14=NA")
data$w1_pvv_govopp<-as.factor(data$w1_pvv_govopp)
levels(data$w1_pvv_govopp) <- c("Populist","Government","Opposition")
data$w1_pvv_govopp <- relevel(data$w1_pvv_govopp, ref = "Populist")

#w1 vote intention PVV-------
data$w1_pvv_national<-ifelse(as.numeric(data$w1_q36)==3,1,0)
data$w1_pvv_EU<-ifelse(as.numeric(data$w1_q34)==3,1,0)
#w4 vote intention PVV-------
data$w4_pvv_national<-ifelse(as.numeric(data$w4_q34)==3,1,0)
data$w4_pvv_EU_vote<-ifelse(as.numeric(data$w4_q7)==2,1,0)

#*Social conservatism-------------
data$immi1<- 8-as.numeric(data$w1_q42_1)
data$immi2<- 8-as.numeric(data$w1_q42_2)
data$immi3<- as.numeric(data$w1_q42_3)
data$immi4<- 8-as.numeric(data$w1_q42_4)
data$immi5<- as.numeric(data$w1_q42_5)
data$w1_immi<-rowMeans(data.frame(data$immi1, data$immi2, data$immi3, data$immi4,data$immi5), na.rm=T)

#Cynicism --------------
data$cyn1<- as.numeric(data$w1_q10_1)
data$cyn2<- as.numeric(data$w1_q10_2)
data$cyn3<- 8-as.numeric(data$w1_q10_3)
data$cyn4<- 8-as.numeric(data$w1_q10_4)
data$w1_cyn<-rowMeans(data.frame(data$cyn1, data$cyn2, data$cyn3, data$cyn4), na.rm=T)

#subset data
data_sub <- subset(data,is.na(rowMeans(with(data,data.frame(w5_open,w5_con, w5_agre))))==F)

save(data_sub, file="Study 1/Altered Data/Study1_NL_14.RData")
